﻿using System;
using System.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Alerts_Administration_2010.classes.controller;
using Alerts_Administration_2010.interfaces.views;
using Alerts_Administration_2010.classes.views;
using Alerts_Administration_2010.interfaces;
using Alerts_Administration_2010.classes;
using System.Web.UI.WebControls;
using Alerts_Administration_2010.classes.views.templates;
using Alerts_Administration_2010.classes.views.Controls;

namespace Alerts_Administration_2010.Layouts.AlertsAdministration2010
{
    public partial class AlertsOverview : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ObjectDataSource1.TypeName = (typeof(AlertsBLL)).AssemblyQualifiedName;
            ObjectDataSource2.TypeName = (typeof(AlertsBLL)).AssemblyQualifiedName;
            
            DetailsView1.ItemCommand += new DetailsViewCommandEventHandler(DetailsView1_ItemCommand);
            GridView1.RowCommand += new GridViewCommandEventHandler(GridView1_RowCommand);
            DetailsView1.ItemUpdated += new DetailsViewUpdatedEventHandler(DetailsView1_ItemUpdated);
        }

        private void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
        {
            GridView1.DataBind();
        }

        private void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select") 
            {
                // GridView1.Visible = false;
                DetailsView1.ChangeMode(DetailsViewMode.Edit);    
            }
        }

        private void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            if ((e.CommandName == "Cancel") || (e.CommandName == "Update")) {
                GridView1.SelectedIndex = -1;
                GridView1.Visible = true;
            }
        }
    }
}
